package com.example.myspring.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.HashOperations;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.Map;

@Service
public class RedisService {


    @Autowired
    private RedisTemplate<String, Object> redisTemplate;


    public void setValue(String key, Object value) {
        redisTemplate.opsForValue().set(key, value);
    }

    public Object getValue(String key) {
        return redisTemplate.opsForValue().get(key);
    }

    public void setHash(String key, Map<String, String> value) {
        HashOperations<String, String, Object> hashOps = redisTemplate.opsForHash();
        hashOps.putAll(key, value);
    }

    public Map<String, Object> getHash(String key) {
        HashOperations<String, String, Object> hashOps = redisTemplate.opsForHash();
        return hashOps.entries(key);
    }
    public Object getHashValue(String key,String id){
        HashOperations<String, String, Object> hashOps = redisTemplate.opsForHash();
        return hashOps.get(key,id);
    }




}